package com.team.lostProperty.service.impl;

import com.team.lostProperty.entity.LikeMap;
import com.team.lostProperty.entity.PushInfo;
import com.team.lostProperty.entity.User;
import com.team.lostProperty.mapper.LikeMapDao;
import com.team.lostProperty.service.LikeMapService;
import com.team.lostProperty.utils.IdWorker;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class LikeMapServiceImpl implements LikeMapService {
    @Resource
    private LikeMapDao likeMapDao;

    private IdWorker idWorker = new IdWorker(1, 1, 1);

    @Override
    public Boolean insertLikeMap(long userId, long pushInfoId, String createdDate) {
        User user = new User();
        user.setUserId(userId);
        PushInfo pushInfo = new PushInfo();
        pushInfo.setPushInfoId(pushInfoId);
        LikeMap likeMap = new LikeMap();
        long likeMapId=idWorker.nextId();
        System.out.println(likeMapId);
        likeMap.setLikeMapId(likeMapId);
        likeMap.setUser(user);
        likeMap.setPushInfo(pushInfo);
        likeMap.setCreatedDate(createdDate);
        try {
            likeMapDao.insertLikeMap(likeMap);
            return true;
        }catch (Exception e){
            System.out.println(e);
        }
        return false;
    }

    @Override
    public List<LikeMap> selectByPushInfoId(long pushInfoId) {
        return likeMapDao.selectByPushInfoId(pushInfoId);
    }

    @Override
    public int deleteById(long id) {
        return likeMapDao.deleteById(id);
    }
}
